package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.db.PageResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.IotHealthDto;
import com.zzyl.nursing.dto.MemberUserAddDto;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 客户老人关联Controller
 *
 * @author ruoyi
 * @date 2025-10-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "客户老人关联的接口")
public class FamilyMemberElderController extends BaseController {

    /**
     * 新增绑定家人
     */
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @PostMapping("/add")
    public R addBindFamily(@RequestBody MemberUserAddDto memberUserAddDto) {
        familyMemberElderService.addBindFamily(memberUserAddDto);
        return R.ok();
    }

    /**
     * 查询家人列表
     */
    @GetMapping("my")
    public R<List<FamilyMemberElderVo>> getFamilyList() {
        List<FamilyMemberElderVo> familyMemberElderVoList = familyMemberElderService.getFamilyList();
        return R.ok(familyMemberElderVoList);
    }

    /**
     * 查看已绑定家人列表（分页查询）
     */
    @GetMapping("list-by-page")
    public R<List<FamilyMemberElderPageVo>> getFamilyListPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        List<FamilyMemberElderPageVo> list = familyMemberElderService.getFamilyListPage(pageNum, pageSize);
        return R.ok(list);
    }

    /**
     * 查看健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public R<DataVo> queryDevicePropertyStatus(@RequestBody IotHealthDto iotHealthDto) {
        DataVo dataVo = familyMemberElderService.QueryDevicePropertyStatus(iotHealthDto);
        return R.ok(dataVo);
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("queryDeviceDataListByDay")
    public R<List<DataTimeDataValueVo>> queryDeviceDataListByDay(DeviceDataDto deviceDataDto) {
        List<DataTimeDataValueVo> dataTimeDataValueVoList = familyMemberElderService.queryDeviceDataListByDay(deviceDataDto);
        return R.ok(dataTimeDataValueVoList);
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping ("queryDeviceDataListByWeek")
    public R<List<DataTimeDataValueVo>> queryDeviceDataListByWeek(DeviceDataDto deviceDataDto){
        List<DataTimeDataValueVo> dataTimeDataValueVoList = familyMemberElderService.queryDeviceDataListByWeek(deviceDataDto);
        return R.ok(dataTimeDataValueVoList);
    }

}
